﻿using AutoMapper.Internal.Mappers;
using Mes.Pendant.UnitMeasures;
using Mes.Pendant.UnitMeasures.Dto;
using Mes.Pendant.UnitMeasureW;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Mes.Pendant.Web.Controllers
{
    public class UnitMeasureController : Controller
    {
        /// <summary>
        /// 显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult UnitIndex()
        {
            return View();
        }

        /// <summary>
        /// 新增视图
        /// </summary>
        /// <returns></returns>
        public IActionResult AddUnitMeasure()
        {
            return View();
        }

        /// <summary>
        /// 修改视图
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateUnitMeasure()
        {
            return View();
        }

        private readonly IUnitMeasureService _unitMeasureService;

        public UnitMeasureController(IUnitMeasureService unitMeasureService)
        {
            _unitMeasureService = unitMeasureService;
        }
        /// <summary>
        /// 获取计量单位列表
        /// </summary>
        /// <param name="customerCode"></param>
        /// <param name="customerName"></param>
        /// <param name="isEffective"></param>
        /// <returns></returns>
        public IActionResult GetCustomerList(string? customerCode, string? customerName, int isEffective, int page=1, int limit=10)
        {
            var (list, total) = _unitMeasureService.GetCustomerList(customerCode, customerName, isEffective,page, limit);
            return Json(new { data=list,count=total,code=0 });
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="unitMeasure"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> CreatUnitMeasureInfo(UnitMeasureDto unitMeasure)
        {
            var unit=await _unitMeasureService.CreatUnitMeasureInfo(unitMeasure);
            return unit;
        }

        /// <summary>
        /// 根据id获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<UnitMeasureDto> GetUnitMeasureById(int id)
        {
            var unit = await _unitMeasureService.GetUnitMeasureById(id);
            return unit;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="unitMeasure"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> UpdateUnitMeasureInfo(UnitMeasureDto unitMeasure)
        {
            var unit = await _unitMeasureService.UpdateUnitMeasureInfos(unitMeasure);
            return unit;
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="unitMeasureId"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> DeleteUnitMeasureInfo(int id)
        {
            var unit=await _unitMeasureService.DeleteUnitMeasureInfo(id);
            return unit;
        }

        /// <summary>
        /// 获取主计量单位
        /// </summary>
        /// <param name="isMainUnit"></param>
        /// <returns></returns>
        public List<UnitMeasureDto> GetMainUnits(int isMainUnit = 1)
        {
            return _unitMeasureService.GetMainUnits(isMainUnit);
        }

    }
}
